import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.io.Serializable;
import java.net.*;

public class RMIClientImp extends UnicastRemoteObject implements RMIClient 
{
	
	public RMIClientImp() throws RemoteException 
	{
		try 
		{
			Naming.rebind("rmi:///Client", this);
			// Suchen des Servers in RMIRegistry
			RMIServer server = (RMIServer) Naming.lookup("rmi://localhost/Server");
			//Ausführen einer Methode im Server
			System.out.println("Client ruft Server Funktion auf");
			Student stud = new Student();
			
			// Leeren Studenen an Server schicken.
			server.setStudent(stud);
		}
		catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		catch (MalformedURLException e) 
		{
			System.out.println("URL ungültig:\n" + e.getMessage());
		}
	}
	
	public static void main(String[] args) {
		try 
		{
			RMIClientImp client = new RMIClientImp();
		} 
		
		catch (RemoteException e) 
		{
			System.out.println("Fehler während Kommunikation:\n"+ e.getMessage());
		}
	}
	
	public void setString (String str) 
	{
		System.out.println (str);
	}

	public void setStudent(Student stud) throws RemoteException 
	{
		System.out.println("Ausgabe von Student nach Server");
		stud.print();
		
		// !!!Beenden des Clients, führt allerdings zu Exceptions beim Server!!!!! 
		System.exit(0); 
	}
}